package jmm;

public class JMMTest {

    private static volatile boolean initFlag = false;
    public static void main(String[] args) {
        new Thread(()->{
            System.out.println("begin...........");
            while(!initFlag){
                int a = 10;
//                initFlag = true;
                //当对initFlag进行一个高频的访问时，initFlag会进入高速缓存存储
                //sleep和wait的区别，wait会释放资源
                //两者都会重新加载高速缓存内容，会释放高速缓存内容
//                System.out.println("waiting.............");

            }
            System.out.println("ending.............");
        }).start();

        try {
            Thread.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(()->{
            prepare();
        }).start();
    }
    public static void prepare(){
        System.out.println("prepare assgin  begin.......");
        initFlag = true;
        System.out.println("prepare assgin  end.......");
    }
}
